package com.example.mongo.rest;

import com.example.mongo.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.Point;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author void
 * @date 2022/1/14 13:49
 * @desc
 */
@RestController
public class ApiTestController {
    
    @Autowired
    private MongoTemplate mongoTemplate;
    
    @GetMapping("/lbs")
    public void lbs(){
        Query query = new Query();
        Criteria criteria = new Criteria("location");
        Point point = new Point(113.95264, 22.53783);
        criteria.nearSphere(point);
        criteria.maxDistance(100);
        query.addCriteria(criteria);
        long count = mongoTemplate.count(query, User.class);
        System.out.println(count);
    }
}
